home *** CD-ROM | disk | FTP | other *** search
/ Atari Forever 4 / Atari Forever 4.zip / Atari Forever 4.iso / FALCON / DEMOSRGB / FD_RGB06 / U_TRACK / EXEMPLE / RECEIVE / RECEIVE.C next >
C/C++ Source or Header  |  1998-03-14  |  6KB  |  224 lines

  1. /* ~~~~~~~~~~~~~~~~~~ */
  2. /* Messages reception */
  3. /* ~~~~~~~~~~~~~~~~~~ */
  4.  
  5. /* -------------------------------------------------------------------- */
  6. /* This source shows how to communicate in two directions with the      */
  7. /* player. These news features were especially added in the player for  */
  8. /* DMViolator :)                                                        */
  9. /* To exit this program, press the '*' key.                                */
  10. /* The best way to test this program is under Multitos with MiNTShell.  */
  11. /* -------------------------------------------------------------------- */
  12.  
  13. /* -------------------------------------------------------------------- */
  14. /* Includes & Defines                                                    */
  15. /* -------------------------------------------------------------------- */
  16.  
  17. #include <aes.h>
  18. #include <vdi.h>
  19. #include <tos.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include "..\u_trax.h"
  24.  
  25. typedef struct
  26.     {
  27.     long    ident;
  28.     union
  29.         {
  30.         void *pt;
  31.         long l;
  32.         int     i[2];
  33.         char c[4];
  34.         }v;
  35.     }COOKIE;
  36.  
  37. #define        FALSE        0
  38. #define        TRUE        1
  39. #define        AP_TERM        50            /* message fin app multitos */
  40.  
  41. void    fin_prg(int);
  42. void    texte(char *);
  43. extern    COOKIE    *get_cookie(long);
  44. extern    long swap(long);
  45. int        event_buffer[8];
  46. int        clavier(int);
  47. int        mesag(void);
  48. int        PLAYER_OUT=FALSE;
  49.  
  50. /* ---------------------------------------------------------------- */
  51. /* Program                                                            */
  52. /* ---------------------------------------------------------------- */
  53.  
  54. int    main(void)
  55.     {
  56.     int     id_appl,trax_id;
  57.     int        event,key,dummy;
  58.     int        fin=FALSE;
  59.     
  60.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  61.     /* Search AES id of the player */
  62.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  63.     
  64.     id_appl=appl_init();
  65.     trax_id=appl_find("U_TRACK ");
  66.  
  67.     if (trax_id<0)
  68.        {    
  69.        COOKIE    *cookie;
  70.  
  71.        cookie=(COOKIE *)malloc(sizeof(COOKIE));
  72.        if (cookie==NULL) fin_prg(-1);
  73.        cookie=get_cookie('UTRK');
  74.        if (cookie==NULL) trax_id=-1;
  75.        else trax_id=cookie->v.i[0];
  76.        free(cookie);
  77.        }
  78.  
  79.     if (trax_id<0)
  80.        {
  81.        printf("\nUltimate Tracker isn't in memory.\n");
  82.        fin_prg(-1);
  83.        }
  84.     
  85.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  86.     /* Send my AES id to the player */
  87.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  88.     
  89.     event_buffer[0]=ID_TRACK;
  90.     event_buffer[1]=T_IDENT;
  91.     event_buffer[2]=id_appl;
  92.     wind_update(BEG_UPDATE);
  93.     appl_write(trax_id,16,event_buffer);
  94.     wind_update(END_UPDATE);
  95.     evnt_timer(1000,0);
  96.     
  97.     /* ~~~~~~~~~ */
  98.     /* Main loop */
  99.     /* ~~~~~~~~~ */
  100.     
  101.     while(!fin)
  102.         {
  103.         event=evnt_multi(MU_KEYBD|MU_MESAG,0,0,0,0,0,0,0,0,0,0,0,0,0,event_buffer,
  104.                          0,0,&dummy,&dummy,&dummy,&dummy,&key,&dummy);
  105.         if (event & MU_KEYBD) fin=clavier(key);
  106.         if (event & MU_MESAG) fin=mesag();
  107.         }
  108.  
  109.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  110.     /* End of program : say to the player i'm gone */
  111.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */    
  112.     
  113.     if    (!PLAYER_OUT)
  114.         {
  115.         event_buffer[0]=ID_TRACK;
  116.         event_buffer[1]=T_FIDENT;
  117.         wind_update(BEG_UPDATE);
  118.         appl_write(trax_id,16,event_buffer);
  119.         wind_update(END_UPDATE);
  120.         evnt_timer(1000,0);
  121.         }
  122.     appl_exit();
  123.     return 0;
  124.     }
  125.     
  126. void fin_prg(int ret)
  127.     {
  128.     appl_exit();
  129.     exit(ret);
  130.     }
  131.     
  132. /* ------------------------------------------------------------------------ */
  133. /* test clavier                                                                */
  134. /* ------------------------------------------------------------------------ */
  135.  
  136. int    clavier(int key)
  137.     {
  138.     if ((char)key=='*') return TRUE;
  139.     return FALSE;
  140.     }
  141.     
  142. /* ------------------------------------------------------------------------ */
  143. /* Message                                                                    */
  144. /* ------------------------------------------------------------------------ */
  145.  
  146. int mesag(void)
  147.     {
  148.     if (event_buffer[0]==AP_TERM) return TRUE;
  149.     if (event_buffer[0]!=ID_REPONSE) return FALSE;
  150.     
  151.     switch(event_buffer[1])
  152.         {
  153.         case R_PLAY:         printf("Playing module...\n");
  154.                              break;
  155.         case R_FORWARD:        printf("Forward...\n");
  156.                             break;
  157.         case R_REWIND:        printf("Rewind...\n");
  158.                             break;
  159.         case R_PAUSE_ON:    printf("Pause ON\n");
  160.                             break;
  161.         case R_PAUSE_OFF:    printf("Pause OFF\n");
  162.                             break;
  163.         case R_STOP:        printf("Stop & clear module.\n");
  164.                             break;
  165.         case R_OPEN:        printf("Opening player window.\n");
  166.                             break;
  167.         case R_CLOSE:        printf("Closing player window.\n");
  168.                             break;
  169.         case R_FREQ:        printf("Changing Frequency to ");
  170.                             switch(event_buffer[2])
  171.                                 {
  172.                                 case 0:    printf("6.25 Khz\n");
  173.                                         break;
  174.                                 case 1: printf("12.5 Khz\n");
  175.                                         break;
  176.                                 case 2: printf("25 Khz\n");
  177.                                         break;
  178.                                 case 3: printf("50 Khz\n");
  179.                                         break;
  180.                                 }
  181.                             break;
  182.         case R_QUIT:        printf("Exiting player. I quit too...\n");
  183.                             PLAYER_OUT=TRUE;
  184.                             return TRUE;
  185.         case R_LOOP_ON:        printf("Switching loop ON.\n");
  186.                             break;
  187.         case R_LOOP_OFF:    printf("Switching loop OFF.\n");
  188.                             break;
  189.         case R_ENDMOD:        printf("End of module.\n");
  190.                             break;
  191.         case R_BEGLOAD:        {
  192.                             char *pm;
  193.                             long ad2,stack;
  194.             
  195.                             /* as the MiNT flag of the player is Super  */
  196.                             /* you have to be in Supervisor mode to get */
  197.                             /* the module filename                        */
  198.                 
  199.                             stack=Super(0L);
  200.                             ad2=event_buffer[2];
  201.                             ad2=swap(ad2);
  202.                             (int)ad2=event_buffer[3];
  203.                             pm=(char *)ad2;
  204.                             printf("Loading %s\n",pm);
  205.                             Super((void *)stack);
  206.                             }
  207.                             break;
  208.         case R_ENDLOAD:        printf("End of loading module.\n");
  209.                             break;
  210.         case R_FAILOAD:        printf("Error during loading module.\n");
  211.                             break;
  212.         case R_MOVE:        printf("Window moved to X=%d, Y=%d\n",event_buffer[2],event_buffer[3]);
  213.                             break;
  214.         case R_POSIT:        printf("Position : %d / %d\n",event_buffer[2]+1,event_buffer[3]);
  215.                             break;
  216.         case R_INFOS:        printf("Informations about the player: \n");
  217.                             printf("Window handle = %d\n",event_buffer[2]);
  218.                             printf("VDI Graphic handle = %d\n",event_buffer[3]);
  219.                             printf("AES Id = %d\n",event_buffer[4]);
  220.                             printf("Version = %c.%c\n",event_buffer[5]+'0',event_buffer[6]+'0');
  221.                             break;
  222.         }
  223.     return FALSE;
  224.     }